//
//  LJM_ActivityMoreVC_ViewController.m
//  wind
//
//  Created by 李金明 on 16/1/20.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJM_ActivityMoreVC_ViewController.h"
#import "LJM_ActivityMoreVC_TableViewCell.h"
#import "LJM_ActivityMoreVC_Model.h"
#import "LJM_RANK_WebView_ViewController.h"
@interface LJM_ActivityMoreVC_ViewController ()<UITableViewDataSource, UITableViewDelegate, RANK_WebView_BackDelegate>
- (void)backRANK_WebView_Delegate;
@property (nonatomic, retain) UIButton *bactButton;
@property (nonatomic, retain) UIView *barview;
@property (nonatomic, retain) UITableView *tableV;
@end

@implementation LJM_ActivityMoreVC_ViewController
- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr) {
        [_dataArr release];
        _dataArr = [dataArr retain];
    }
    
    
    [self.tableV reloadData];
}
- (void)dealloc
{
    self.backDelegate = nil;
    [_dataArr release];
    [_tableV release];
    [_bactButton release];
    [_barview release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self navigationBarView];
    [self addTableView];
}
#pragma 自定义navigationBar
- (void)navigationBarView
{
    
    self.barview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, NAVIGATIONBARHEIGHT)];
    self.barview.userInteractionEnabled = YES;
    self.barview.backgroundColor = [UIColor colorWithRed:69 / 255.0 green:175 / 255.0 blue:248 / 255.0 alpha:1.0];
    [self.navigationController.navigationBar addSubview:self.barview];
    [_barview release];
    self.bactButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bactButton setTitle:@"返回" forState:UIControlStateNormal];
    [self.bactButton addTarget:self action:@selector(backButton) forControlEvents:UIControlEventTouchUpInside];
    [self.bactButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.barview addSubview:self.bactButton];
    [self.bactButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.barview.mas_left).offset(10);
        make.width.mas_equalTo(@50);
        make.bottom.equalTo(self.barview.mas_bottom).offset(-5);
        make.height.mas_equalTo(@30);
    }];
    UILabel *titleLab = [[UILabel alloc] init];
    titleLab.text = @"活动专区";
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.font = [UIFont boldSystemFontOfSize:20];
    titleLab.textColor = [UIColor whiteColor];
    [self.barview addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.barview.mas_centerX);
        make.width.mas_equalTo(@100);
        make.centerY.equalTo(self.bactButton.mas_centerY);
        make.height.mas_equalTo(@30);
    }];
    
}
#pragma 返回的动作
- (void)backButton
{
    [self.navigationController popViewControllerAnimated:YES];
    [self.barview removeFromSuperview];
    [self.backDelegate backActionMoreVCAction];
}
#pragma 添加tableView
- (void)addTableView
{
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 50) style:UITableViewStylePlain];

    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableV];
    [_tableV release];
    
    //用自定义cell的时候创建重用池
    //UINib是用于从XIB中获取信息的
    UINib *nib = [UINib nibWithNibName:@"LJM_ActivityMoreVC_TableViewCell" bundle:[NSBundle mainBundle]];
    [self.tableV registerNib:nib forCellReuseIdentifier:@"cell"];
    
    
}
#pragma tableView的协议方法
#pragma 数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.dataArr.count;
}
#pragma 高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 160;
}
#pragma cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    LJM_ActivityMoreVC_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (0 != self.dataArr.count) {
        LJM_ActivityMoreVC_Model *model = [self.dataArr objectAtIndex:indexPath.row];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:model.picUrl] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.titleLab.text = model.name;
        cell.subTitleLab.text = model.desc;
        
        cell.dateLab.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    }
    
    return cell;

}

#pragma 点击cell的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LJM_RANK_WebView_ViewController *webView = [[LJM_RANK_WebView_ViewController alloc] init];
    webView.backDelegate = self;
    webView.navigationItem.hidesBackButton = YES;
   LJM_ActivityMoreVC_Model *model = [self.dataArr objectAtIndex:indexPath.row];
    webView.url = model.actionUrl;
    [self.barview removeFromSuperview];
    [self.navigationController pushViewController:webView animated:YES];
    [webView release];

}
#pragma webView返回的协议方法
- (void)backRANK_WebView_Delegate
{
    [self navigationBarView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
